<?php
class Works extends MY_Controller{

	function __construct(){
		parent::__construct();
	}


	function index(){
		$data['works'] = work::find('all',array('conditions'=>array('active'=>1),'order'=>'position asc'));
		$data['title'] = $this->title('Works');
		$this->load->view('default/header',$data);
		$this->load->view('default/works');
		$this->load->view('default/footer');

	}

	function item()
	{
		$id = $this->uri->segment(2);
		if($id != NULL && is_numeric($id)){
				
			$work = work::find_by_id($id);

			if($work->active == 1){
				if($work->tag != NULL){
					$tagItems = explode(',',$work->tag);
					$data['tags'] = tag::find('all', array('conditions' => array('id in (?)', $tagItems)));
				}
				$data['work'] = $work;
				$data['title'] = $this->title('Works | '.$work->name);
				$data['photos'] = photo::find('all',array('conditions'=>array('work_id'=>$id),'order'=>'position asc'));
				$this->load->view('default/header',$data);
				$this->load->view('default/item');
				$this->load->view('default/footer');
			}else{
				redirect('works');
			}
		}else{
			redirect('works');
		}
	}
}